package tron.entity;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 一对一演示
 * 主表保存子表id作为外键
 */

@Entity
public class User {
    @Id
    private String id;
    private String name;
    private String gender;
    private Integer age;
    private LocalDateTime birthday;
    @Column(name = "user_info_id")
    private String userInfoId;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "user_info_id",insertable = false,updatable = false)
    private UserInfo userInfo;

    @OneToMany(mappedBy = "user",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private Set<Children> children;

    @ManyToMany
    @JoinTable(name = "user_game",joinColumns = @JoinColumn(name = "user_id"),inverseJoinColumns = @JoinColumn(name = "game_id"))
    private Set<Game> games;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public LocalDateTime getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDateTime birthday) {
        this.birthday = birthday;
    }

    public String getUserInfoId() {
        return userInfoId;
    }

    public void setUserInfoId(String userInfoId) {
        this.userInfoId = userInfoId;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public Set<Children> getChildren() {
        return children;
    }

    public void setChildren(Set<Children> children) {
        this.children = children;
    }

    public Set<Game> getGames() {
        return games;
    }

    public void setGames(Set<Game> games) {
        this.games = games;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                ", userInfoId='" + userInfoId + '\'' +
                ", userInfo=" + userInfo +
                ", children=" + children +
                ", games=" + games +
                '}';
    }
}
